package com.twu.biblioteca.repository;

import com.twu.biblioteca.domain.LibraryEntity;

import java.util.Collections;
import java.util.List;


public class LibraryEntityRepository<T extends LibraryEntity> implements Repository<T> {
    private final List<T> dataSet;

    public LibraryEntityRepository(List<T> initialDataSet) {
        this.dataSet = initialDataSet;
    }

    @Override
    public List<T> getAll() {
        return dataSet;
    }

    @Override
    public boolean remove(T object) {
        int index = Collections.binarySearch(dataSet, object, null);
        if(index != -1)
            dataSet.remove(index);
        return false;
    }

    @Override
    public void add(T object) {
        dataSet.add(object);
    }
}
